package com.example.iot.util;

import java.io.*;

/**
 * @author : Lin
 * @version : [v1.0]
 * @className : TxtUtil
 * @description : 描述说明该类的功能
 * @createTime : 2023/7/2 19:27
 * @updateUser : Lin
 * @updateTime : 2023/7/2 19:27
 * @updateRemark : 描述说明本次修改内容
 */

public class TxtUtil {
    static public void Write(String path,String val){
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(path))) {
            writer.write(val); // 将数据写入文件
            System.out.println("token更新成功");
            System.out.println(val);
        } catch (IOException e) {
            System.err.println("写入文件时发生错误：" + e.getMessage());
        }
    }
    static public String Read(String path) {
        String res = null;
        try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
            while ((res = reader.readLine()) != null) {
                System.out.println(res); // 按行输出读取到的数据
                return res;
            }
        } catch (IOException e) {
            System.err.println("读取文件时发生错误：" + e.getMessage());
            return null;
        }
        return res;
    }
}
